/************************************************************************
 * Copyright (c) 2008 Sergei Stolyarov
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * This file contains implementation of configuration parameters repository,
 * it maintains settings and all other components must ask for settings
 * from manager.
 ************************************************************************/

#include <QSettings>

#include "configholder.h"

ConfigHolder* ConfigHolder::instance = 0;

ConfigHolder::ConfigHolder()
{
    // load configuration settings from global file and from user file
    // global file is "/etc/xdg/eeetune.ini"
    // local file is "~/.config/eeetune.ini"

    settings = new QSettings(QSettings::IniFormat, QSettings::UserScope,
        config::APPLICATION_NAME);
    
}

int ConfigHolder::refreshInterval()
{
    return settings->value(QString("general/refresh_interval"), 0).toInt();
}

void ConfigHolder::setRefreshInterval(int value)
{
    settings->setValue(QString("general/refresh_interval"), value);
}

int ConfigHolder::fanSpeed()
{
    return settings->value(QString("general/fan_speed"), -1).toInt();
}

void ConfigHolder::setFanSpeed(int value)
{
    settings->setValue(QString("general/fan_speed"), value);
}

bool ConfigHolder::fanManual()
{
    return settings->value(QString("general/fan_manual"), false).toBool();
}

void ConfigHolder::setFanManual(bool value)
{
    settings->setValue(QString("general/fan_manual"), value);
}

bool ConfigHolder::showLedIcons()
{
    return settings->value(QString("general/show_led_icons"), true).toBool();
}

void ConfigHolder::setShowLedicons(bool show)
{
    settings->setValue(QString("general/show_led_icons"), show);
}

bool ConfigHolder::allowTemperatureNotifications()
{
    return settings->value(QString("temp_notifications/enabled"), false).toBool();
}

void ConfigHolder::setAllowTemperatureNotifications(bool allow)
{
    settings->setValue(QString("temp_notifications/enabled"), allow);
}

int ConfigHolder::criticalTemperature()
{
    return settings->value(QString("temp_notifications/critical_temperature"), 60).toInt();
}

void ConfigHolder::setCriticalTemperature(int t)
{
    if (t < 0 || t > 100) {
        t = 60;
    }
    settings->setValue(QString("temp_notifications/critical_temperature"), t);
}

QString ConfigHolder::criticalTemperatureNotification()
{
    return settings->value(QString("temp_notifications/notification_text"), QString("Critical temperature reached!")).toString();
}

void ConfigHolder::setCriticalTemperatureNotification(QString text)
{
    settings->setValue(QString("temp_notifications/notification_text"), text);
}

ConfigHolder* ConfigHolder::getInstance()
{
    if (0 == instance) {
        instance = new ConfigHolder();
    }

    return instance;
}


